-- local colors = require("galaxyline.themes.colors").doom-one
vim.o.relativenumber = true
vim.o.number = true
vim.o.noexpandtab = true
vim.o.softtabstop = 2
vim.o.showtabline = 2
vim.o.termguicolors = true
vim.o.cursorline = true
vim.o.mouse = 'a'
vim.o.scrolloff = 4
vim.o.expandtab = true
vim.o.smartindent = false
vim.o.autoindent = false
vim.o.tabstop = 2
vim.o.shiftwidth = 2
vim.o.wildmenu = true
vim.o.ignorecase = true
vim.o.swapfile = true

vim.cmd('hi Normal ctermfg=252 ctermbg=none')

vim.cmd('let g:python3_host_prog = "/usr/bin/python3"')

-- vim.cmd('set mouse+=a')

--vim.o.autochdir = true
vim.o.t_Co = 256

-- vim.cmd('set term=xterm')
-- vim.cmd('set t_Co=256')
-- vim.cmd('let g:rehash256 = 1')

vim.cmd('syntax on')
vim.cmd('filetype plugin indent on')
-- vim.cmd('let autosave=30')
vim.o.autoread = true
vim.o.ruler = true
vim.o.exrc = true
vim.o.secure = true
--vim.o.hidden = true
vim.o.list = true

--vim.o.ttimeoutlen = 0
--vim.o.notimeout = true
-- vim.o.viewoptions = 'cursor,folds,slash,unix'
vim.o.wrap = true
vim.o.re = 0
vim.o.tw = 0
vim.o.foldmethod = 'expr'
vim.o.foldexpr = 'nvim_treesitter#foldexpr()'
vim.o.foldenable = false
vim.o.foldlevel = 99

vim.o.splitright = true
vim.o.splitbelow = true
vim.o.noshowmode = true
vim.o.showcmd = true
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.inccommand = 'split'
-- vim.o.completeopt = 'longest,noinsert,menuone,noselect,preview'

-- Markdown-Preview.nvim
--vim.g.mkdp_filetypes = { 'markdown' }
--vim.cmd('autocmd vimenter *.md exec ":MarkdownPreview"')

-- 记录光标位置
-- vim.cmd([[au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif']])
-- vim.cmd([[ autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]])


-- set nofoldenable
-- au BufRead * normal zR
-- autocmd BufWinEnter * silent! :%foldopen!
-- autocmd BufWinEnter * let &foldlevel = max(map(range(1, line('$')), 'foldlevel(v:val)')) 
--
-- autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif


-- 文件操作：Backup&Undo
vim.cmd([[

  silent !mkdir -p ~/.config/nvim/tmp/backup
  silent !mkdir -p ~/.config/nvim/tmp/undo
  "silent !mkdir -p ~/.config/nvim/tmp/sessions
  set backupdir=~/.config/nvim/tmp/backup,.
  set directory=~/.config/nvim/tmp/backup,.
  if has('persistent_undo')
    set undofile
    set undodir=~/.config/nvim/tmp/undo,.
  endif


]])


-- au BufReadPost * if line("'"") > 0|if line("'"") <= line("$")|exe("norm '"")|else|exe "norm $"|endif|endif

vim.cmd([[

autocmd BufRead * autocmd BufWinEnter * ++once normal! zx

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif


]])

-- 中文乱码
vim.o.regexpengine=1
vim.o.termencoding='UTF-8'
vim.o.encoding='UTF-8'
vim.o.fileencodings='UTF8,UCS-BOM,GBK,CP936,GB2312,GB18030'



-- vim.cmd('let g:lightline={ "enable": {"statusline": 1, "tabline": 0} }')


-- Necessary Commands to Execute
vim.cmd('exec "nohlsearch"')

-- GitGutter 保存时更新git状态
vim.cmd('autocmd BufWritePost * GitGutter')


--中英文输入法切换
vim.cmd([[

let g:input_toggle = 1
function! Fcitx2en()
  let s:input_status = system("fcitx5-remote")
  if s:input_status == 2
    let g:input_toggle = 1
    let l:a = system("fcitx5-remote -c")
  endif
endfunction

function! Fcitx2zh()
  let s:input_status = system("fcitx5-remote")
  if s:input_status != 2 && g:input_toggle == 1
    let l:a = system("fcitx5-remote -o")
    let g:input_toggle = 0
  endif
endfunction

autocmd InsertLeave * call Fcitx2en()

]])

